<?php
//商品评分系统
namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Requests;

class ScoreController extends CommonController
{
    //商品评分信息浏览
    public function index()
    {	
		//商品评分相关信息表
		$infotb = \DB::table("m_info");
		$scorestb = \DB::table("m_scores");
		
		//获取评分用户信息
		$data = $scorestb->paginate(2);
		
		//判断并封装搜索条件
		$params = array();
		if(!empty($_GET['name'])){
			$mid = $infotb->where("name","like","%{$_GET['name']}%")->value("mid");
			$data = $scorestb->where("id",$mid)->paginate(5);
			 //维持搜索条件
			$params['name'] = $_GET['name'];
		}
		
		//遍历当前数据并添加用户信息
		foreach($data as $v){
			$user = \DB::table("m_score")->where('bid',$v->mid)->orderBy('score', 'asc')->first();
			$v->uid = $user->uid;
			$v->score = $user->score;
			$v->stime = $user->stime;
		}
		
		//遍历当前数据并添加商品别名称
		foreach($data as $v){
			$name = \DB::table("u_user")->where("id",$v->uid)->value("uname");
			//放值替换用户ID
			$v->uid = $name; 
		}
		
		//遍历当前数据并添加商品别名称
		foreach($data as $v){
			$v->mmid = $v->mid;
			$name = \DB::table("m_info")->where("mid",$v->mid)->value("name");
			//放值替换商品ID
			$v->mid = $name;
		}
		return view("admin.score.index",['list'=>$data,'user'=>$user,'params'=>$params]);
	}
	
	//加载添加页面
    public function create()
    {
        
    }
	
	//添加链接
    public function store(Request $request)
    {	

    }
	
    public function show($id)
    {
		$data = \DB::table("m_info")->where('mid',$id)->first();
		$link = \DB::table('m_score')->where('bid',$id)->orderBy('score', 'asc')->paginate(2);
		
		foreach($link as $v){
			$name = \DB::table("u_user")->where("id",$v->uid)->value("uname");
			$v->name = $name; //放置进去
		}
		
        return view("admin.score.show",['list'=>$data,'link'=>$link]);
    }

    //加载修改页面
    public function edit($id)
    {
		
    }
	
	//修改链接
    public function update(Request $request, $id)
    {	
		
    }
	
	//删除友情链接
    public function destroy($id)
    {	
       
    }
}
